const app = getApp();
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    CustomBar: app.globalData.CustomBar,
    list: []
  },
  attached: function () {
    var that = this;
    getData(that, "");
  },
  methods: {
    getData(e) {
      var val = e.detail.value;
      var that = this;
      getData(that, val);
    },
    toReply(e) {
      var id = e.currentTarget.dataset.id;
      app.globalData.id = id;
      wx.navigateTo({
        url: '/pages/reply/reply?id=' + id
      });
    },
    imageErrorCallback(e) {
      console.error('图片加载失败', e.detail.errMsg);
    }
  }
});

function getData(that, val) {
  var get_url = app.globalData.local_url + "api/getVideoList"; // 使用原有的接口

  wx.request({
    url: get_url,
    data: {},
    method: 'POST',
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      if (res.data.code == 200) {
        console.log(res.data.data);
        // 假设返回的数据结构中包含 gif 字段
        that.setData({
          list: res.data.data.map(item => ({ ...item, gif: item.video })) // 将 video 字段作为 gif 字段使用
        });
      } else {
        // 处理错误情况
      }
    }
  });
}